<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSocket Server Test Client</title>
</head>
<body>
    <br><br>
    视频监控告警信息-推送测试
    <br><br>
    <form onsubmit="return false" style="align-content: center">
        <input type="text" id="url" value="ws://localhost:9263/alarm" style="font-size: 14px;width: 400px;"/>
        <input type="text" id="message" name="message" value="{'type': 'HANDSHAKE', 'data': {'sessionId': 32999}}" style="width: 400px;"/> &nbsp;
        <input type="button" onclick="sendMsg(this.form.message.value)" value="握手"/><br><br>响应：<br>
        <textarea id="response" name="response" style="width: 70%;height: 300px;"></textarea>
    </form>

    <script>
        var url = document.getElementById("url").value;
        var ws = new WebSocket(url);
        ws.onopen = function () {
            var handshakeMsg = {
                "type": "HANDSHAKE",
                "data": {"sessionId": 32999}
            };
//            ws.send(JSON.stringify(handshakeMsg));
        };
        ws.onerror = function (error) {
          console.log(error);
            document.getElementById("response").value += "error: " + error + "\n";
        };
        ws.onmessage = function (event) {
            document.getElementById("response").value += event.data + "\n";
        };
        ws.onclose = function () {
            console.log("closed");
            document.getElementById("response").value += "server closed" + "\n";
//            ws = new WebSocket("ws://localhost:8282/alarm");  //此处做重连机制
        };
        function sendMsg(msg) {
            if(window.WebSocket && ws.readyState == WebSocket.OPEN){
                ws.send(document.getElementById("message").value);
            }
        }
    </script>

</body>
</html>